﻿package com.PlantVsZombies.Plants;

import java.awt.Graphics;

import com.PlantVsZombies.Bullet.Bomb;
import com.PlantVsZombies.common.Plant;
import com.PlantVsZombies.constant.PlantType;
import com.PlantVsZombies.ui.PlantsMap;
import com.PlantVsZombies.util.ImageUtil;
import com.PlantVsZombies.util.MusicPlay;
import com.PlantVsZombies.util.MusicUtil;

public class CherryPlant extends Plant implements Runnable {

	MusicPlay mp = new MusicPlay(MusicUtil.EXPLOSION);
	public CherryPlant(int x, int y) {
		this.x = x;
		this.y = y;
		this.plantImage = ImageUtil.CHERRY;
		this.life = 12;
	}

/*	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (true) {
			if (life > 0)
				life--;
			if(life==0){
				this.isLive = false;
				Bomb b =new Bomb(this.x-150, this.y-100, ImageUtil.CHERRYBOMB.getImage());
				b.start();
				PlantsMap.bomb.add(b);
				mp.replay();
				return;
			}
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}*/

	@Override
	public PlantType getType() {
		// TODO Auto-generated method stub
		return PlantType.Cherry;
	}

	@Override
	public void drawMe(Graphics g, int x2, int y2) {
		// TODO Auto-generated method stub
		g.drawImage(plantImage.getImage(), x2, y2, null);
	}

	@Override
	public void shootBullet() {
		// TODO Auto-generated method stub

	}

	@Override
	public int doRun() {
		// TODO Auto-generated method stub
		if (life > 0)
			life--;
		if(life==0){
			this.setLive(false);
			Bomb b =new Bomb(this.x-150, this.y-100, ImageUtil.CHERRYBOMB.getImage());
			new Thread(b).start();
			PlantsMap.bomb.add(b);
			mp.replay();
			return 0;
		}
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 1;
	}

}
